#include<iostream>
#include<cstdio>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
using namespace std;


int main()
{
  pid_t id=fork();
  if(id == 0)
  {
    char * const argv[]={(char*)"ls",(char*)"-a",(char*)"-l",(char*)"--color",nullptr};
    (void)argv;

    execlp("ls","ls","-a","--color","-l");
    //execv("/CloudrResetPwdAgentsr/bin/ls",argv);
    //sleep(3);
    //child
    //execl("/bin/ls","ls","-l","--color","-a",nullptr);
    //如果成功是不会走到这里的，如果失败的，就返回错误码1
    exit(1);
  }
  //这里只能是父进程
  pid_t rid=waitpid(id,nullptr,0);//阻塞等待
  if(rid>0)
  {
    printf("等待子进程成功！\n");
  }
  //int n=execl("/bin/ls","ls","-l","-a",nullptr);
  //printf("execl return val:%d\n",n);
  //execl("/bin/top","top",nullptr);
  //printf("我是myexec，pid：%d\n",getpid());
  //execl("./other","other",nullptr);
  return 0;
}
